import * as moment from 'moment';
import * as _ from 'lodash';

export class MomentHelper {
    static add8Hours(value?: moment.Moment): moment.Moment {
        if (!value) { return value; }
        return value.isValid() ? value.add(8, 'h') : value;
    }

    static getTimestamps(): string {
        return moment().format('x');
    }

    static getTimestampsWithRandom(): string {

        const random = Math.ceil(Math.random() * 10000);
        const randomStr = _.padStart(random.toString(), 4, '0');
        return moment().format('x') + randomStr;
    }


    static format(value: moment.Moment, format: string = 'YYYY-MM-DD'): string {
        if (value.isValid()) {
            return value.format(format);
        } else {
            return value.toString();
        }
    }

}
